package com.example.filesynsystem.exception;

import com.example.filesynsystem.pojo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

public class GlobalDefaultException {
    private static Logger logger = (Logger) LoggerFactory.getLogger(GlobalDefaultException.class);

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public Result errorHandle(BusinessException ex, HttpServletResponse response) {
        logger.error(ex.getMessage());
        logger.error(ex.getDetailMessage());
        return ex.getErrorResult();
    }
}
